package com.liuyu.mall2.controller.admin;

import com.liuyu.mall2.entity.Manager;
import com.liuyu.mall2.service.ManagerService;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author 刘宇
 * @classname LoginController
 * @time 2025/4/15
 * @project mall2
 */
@Controller
@RequestMapping("/admin")
public class LoginController {
    @Autowired
    private ManagerService managerService;
@GetMapping("/login")
    public String login(){
    return "login";
}
@PostMapping("/login")
    public String login(String account, String password, Model model, HttpSession session){
    System.out.println("账号："+account+"密码："+password);
    Manager m=managerService.login(account,password);
    if(m==null){
        model.addAttribute("msg","账号或密码错误");
        return "login";
    }
    session.setAttribute("manager",m);
    return "index";
}
}


